﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Npgsql;
using SmartRS.com.vn.smartrs.util;
using SmartRS.com.vn.smartrs.domain;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;
using SmartRS.com.vn.smartrs.dao;

namespace SmartRS.com.vn.smartrs.form.uC
{
    public partial class ucLogin : UserControl
    {
        public ucLogin()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
           // NHibernateHelper.OpenSession();
           // loadNHibernateCfg();
            //txtUsername.AppendText("tan");
            //txtPassword.AppendText("123");
            //FoodKindDao fkDao = new FoodKindDao();
            //var l = fkDao.getAll();
           // var i = fkDao.getById(1);

            FoodKindDao fkDao = FoodKindDao.getInstance();
            FoodKind fk = new FoodKind {foodKindName = txtUsername.Text };
            fkDao.insert(fk);

    
         //  var foodkind = new FoodKind {foodKindName = "Lau" };
           //fkDao.add(foodkind);


            //new FoodKindDao().getFooKindByName("sup");
            Console.WriteLine("------------------------lod------------------------");




            /*NpgsqlConnection connection = InitDB.createConnection();

            NpgsqlCommand cmd = new NpgsqlCommand("SELECT * FROM account WHERE username = '" +txtUsername.Text +"' AND password = '" + txtPassword.Text + "'", connection);

            NpgsqlDataReader dataReader = cmd.ExecuteReader();

            if (dataReader.Read())
            {
                //update state login
                Const.isLogin = true;

                //create main form
                frmMain main = new frmMain();
                //show main form
                main.Show();

                //get parent
                Form myParent = (Form)this.Parent;
                //hide parent
                myParent.Hide();

                //closing data stream
                dataReader.Close();
            }
            else
            {
                //show message error
            }*/

        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        public void loadNHibernateCfg()
        {
            var cfg = new Configuration();
            cfg.Configure();
         //   cfg.AddAssembly(typeof(FoodKind).Assembly);
          new SchemaExport(cfg).Execute(true, true, false);
        }
    }
}
